app.controller('updatePwdCtrl',['$scope','ApiUtil','sweetAlertUtil',function($scope,ApiUtil,sweetAlertUtil){
	$scope.pwd = {
		u_password: '',
		again_pwd: ''
	}

	$scope.update = function($event){
		// var reg = /(?=.*\d)(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,16}/
		if($scope.pwd.u_password.length>16 || $scope.pwd.u_password.length<6){
			sweetAlertUtil.fail('密码格式不正确');
			return;
		}
		if($scope.pwd.u_password != $scope.pwd.again_pwd){
			sweetAlertUtil.fail('两次密码输入不一致');
			return;
		}
		$($event.target).attr('disabled','disabled');
		ApiUtil.put('/api/login/resetPassword',{password:$scope.pwd.u_password}).then(function(res){
			$($event.target).removeAttr('disabled');
			if(res.code == 200){
				sweetAlertUtil.success('密码修改成功');
				window.location.reload(true);
			}else{
				sweetAlertUtil.fail(res.msg);
			}
		}, function(){
			$($event.target).removeAttr('disabled');
			sweetAlertUtil.fail('服务器错误');
		});
		return false;
	}
}]);